package dfl.bysj.controller;


import dfl.bysj.config.RedisKey;
import dfl.bysj.config.model.VO.UserDto;
import dfl.bysj.entity.Advice;
import dfl.bysj.entity.AdviceVO;
import dfl.bysj.handler.NoAuth;
import dfl.bysj.result.R;
import dfl.bysj.service.AdviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author DFL
 * @since 2022-04-26
 */
@Slf4j
@RestController
@RequestMapping("/advice")
public class AdviceController {

    AdviceService adviceService;

    RedisTemplate redisTemplate;

    @Autowired
    public void setRedisTemplate(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Autowired
    public void setAdviceService(AdviceService adviceService) {
        this.adviceService = adviceService;
    }

    @NoAuth
    @GetMapping("/list")
    public R list(){
        List<AdviceVO> adviceList=adviceService.getAllAdvicesFormatTime();
        return R.ok().data("advices",adviceList);
    }

    @PostMapping("/insert")
    public R insert(Advice advice){
        adviceService.insertAdvice(advice);
        return R.ok();
    }

    @PostMapping("/update")
    public R update(Advice advice){
        adviceService.updateAdvice(advice);
        return R.ok();
    }

    @GetMapping("/delete")
    public R delete(String advId){
        adviceService.deleteAdvice(advId);
        return R.ok();
    }
}

